package com.tanhua.server.controller;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;

    /*首次登录---完善信息*/
    @PostMapping("/loginReginfo")
    public ResponseEntity loginReginfo(@RequestBody UserInfo userInfo) {
        //添加用户ID
        userInfo.setId(UserHolder.getUserId());
        //调用service保存
        userInfoService.save(userInfo);
        return ResponseEntity.ok(null);
    }

    /*首次登录---补充头像*/
    @PostMapping("/loginReginfo/head")
    public ResponseEntity updateUserInfo(MultipartFile headPhoto) throws IOException {
        //调用service上传头像
        userInfoService.updateHead(headPhoto);
        return ResponseEntity.ok(null);
    }

}
